package com.flying.server.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

@Data
@NoArgsConstructor
public class Tweet {
    private String id;
    private String author;
    private String body;
    private LocalDate date;

    public Tweet(String author, String body) {
        this.id = UUID.randomUUID().toString();
        this.author = author;
        this.body = body;
        this.date = getRandomDate();
    }

    public static Tweet of(Tweet tweet) {
        return new Tweet(tweet.getAuthor(), tweet.getBody());
    }

    private LocalDate getRandomDate() {
        ThreadLocalRandom r = ThreadLocalRandom.current();
        return LocalDate.of(r.nextInt(1990, 2020), r.nextInt(1, 13), r.nextInt(1, 28));
    }
}
